# This Python file uses the following encoding: utf-8
from django.db import models
from django.contrib.auth.models import User
from cicles.models import Cicle
from curriculums.models import ModulProfessional, UnitatFormativa

class Perfil(models.Model):
    usuari = models.OneToOneField( User, db_index = True )
    
    unitats_formatives_preferides = models.ManyToManyField( UnitatFormativa )
    avatar = models.URLField( u'Avatar from gravatar', max_length = 300 , blank = True)

    class Meta:
        db_table = u'pefils_d_usuari'
        verbose_name = u'Perfil'
        verbose_name_plural = u'Perfils'

#------------------------------------------------------------------------
#https://docs.djangoproject.com/en/1.4/topics/auth/#storing-additional-information-about-users
from django.db.models.signals import post_save
def crea_perfil_d_usuari(sender, instance, created, **kwargs):
    if created:
        Perfil.objects.create(usuari=instance)

post_save.connect(crea_perfil_d_usuari, sender=User)        
